﻿namespace Raffles.OA.Utility
{
    public class ApiResult<T> where T : new()
    { 
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; } = true;

        /// <summary>
        /// 是否弹窗显示
        /// </summary>
        public bool IsPopUpMsg { get; set; } = false;

        /// <summary>
        /// 提示消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 自定义返回数据
        /// </summary>
        public T Data { get; set; } = new T();

        /// <summary>
        /// 成功返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ApiResult<T> Success(T data, bool isPopup=false, string message = "成功")
        {
            return new ApiResult<T>() { IsSuccess = true, IsPopUpMsg = isPopup, Message = message, Data = data };
        }
        /// <summary>
        /// 错误返回
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ApiResult<T> Error(string message = "失败", bool isPopup = false, T data = default)
        {
            return new ApiResult<T>() { IsSuccess = false, IsPopUpMsg = isPopup, Message = message, Data = data };
        }
    }
}